<template>
  <dt-modal-edit
    ref="edit"
    :title="title"
    :label-width="90"
    okText="确认"
    :width="450"
    @ok="onOk"></dt-modal-edit>
</template>

<script>
  import editMgr from '../opt/edit.js'
  import paymentMgr from '@/biz/commission/payment.js'
  import fileMgr from '@/biz/file'

  export default {
    data() {
      return {
        info: {},
        title: '发起佣金回款',
        backId: null
      }
    },
    mounted() {},
    methods: {
      create(backId) {
        this.backId = backId
        this.info = {
          housesId: '',
          backAmount: '',
          backType: 'normal',
          backDate: '',
          remark: '',
          attaches: null
        }
        this.show()
      },
      show() {
        this.$refs.edit.show(editMgr.options(this), this.info)
      },
      hide() {
        this.$refs.edit.hide()
      },
      update() {
        this.$refs.edit.update(editMgr.options(this))
      },
      onOk() {
        if (this.backId) {
          fileMgr
            .uploadAttach(
              'COMMISSION_BACK',
              this.backId,
              this.info.attaches.map((item) => ({ name: item.fileName, url: item.attachAddress }))
            )
            .then((res) => {
              this.$Message.success('操作成功')
              this.hide()
              this.$emit('success')
            })
        } else {
          paymentMgr.apply(this.info).then((res) => {
            this.$Message.success('操作成功')
            this.hide()
            this.$emit('success')
          })
        }
      }
    }
  }
</script>

<style></style>
